from django.shortcuts import render
from rest_framework.viewsets import ModelViewSet
from rest_framework import permissions

from .models import Blog, Comment
from .serializers import BlogSerializer, CommentSerializer


class BlogViewSet(ModelViewSet):
    queryset = Blog.objects.all().order_by('-create_time')
    serializer_class = BlogSerializer
    # permission_classes = [permissions.IsAuthenticated]
    permission_classes = [permissions.IsAuthenticatedOrReadOnly]
    # authentication_classes = [MyAuthentication]


class CommentViewSet(ModelViewSet):
    queryset = Comment.objects.all().order_by('-create_time')
    serializer_class = CommentSerializer
    # permission_classes = [permissions.IsAuthenticated]
    permission_classes = [permissions.IsAuthenticatedOrReadOnly]
    # authentication_classes = [MyAuthentication]
